<template>
    <view>
        <div style="display: flex; margin-bottom: 10px; background-color: white; padding: 15px;">
            <div>
                <image :src="objParams.tbOrderGoods.image ? objParams.tbOrderGoods.image + '?imageView2/1/w/100/h/100' : '/pages/sub/sub1-tabs/static/default-image/goods.jpg'"
                       mode="aspectFill" style="width: 100px; height: 100px;"></image>
            </div>
            <div style="padding-left: 10px;">
                <div style="font-size: 14px;">
                    {{ objParams.tbOrderGoods.title }}
                </div>
                <div style="font-size: 12px; color: grey;">
                    {{objParams.tbOrderGoods.specName}}
                    <label v-if="objParams.tbOrderGoods.colorId">;{{objParams.tbOrderGoods.colorName}}</label>
                </div>
                <div style="width: 100%; font-size: 12px;">
                    申请数量：{{objParams.quantity}}
                </div>
                <div style="width: 100%; text-align: right; padding-right: 5px;" v-if="objParams.payMode === '0' && objParams.afterSaleType === '1'">
                    退款金额：<label style="color: red;">￥{{(objParams.refundMoney) | toFixed2}}</label>
                </div>
            </div>
        </div>
        <div style="padding: 15px;">
            <u-form ref="validateFormRef" :model="validateForm.value" :label-width="150">
                <u-form-item label="快递公司" prop="logisticsCompanyName" required>
                    <u-input v-model="validateForm.value.logisticsCompanyName" type="select" placeholder="请选择快递公司" right-icon="arrow-right"
                             @click="navigateTo(`/pages/common/logistics-company-select/index`, null, validateForm.value)"/>
                </u-form-item>
                <u-form-item label="快递单号" prop="logisticsNo" required>
                    <u-input v-model="validateForm.value.logisticsNo" placeholder="请输入快递单号"/>
                </u-form-item>
                <u-form-item label="备注" prop="progress2Remark">
                    <u-input type="textarea" height="40" v-model="validateForm.value.progress2Remark"/>
                </u-form-item>
            </u-form>
            <u-button type="error" @click="submit()">提交</u-button>
        </div>
    </view>
</template>

<script>

    import {CommonUtil} from "@/dev/core/utils/common.util";
    import {TbOrderGoodsAfterSaleService} from "@/dev/services/tb-order-goods-after-sale.service";

    export default {
        data() {
            return {
                validateForm: {
                    value: {
                        logisticsCompanyType: '',
                        logisticsCompanyName: '',
                        logisticsNo: '',
                        progress2Remark: ''
                    },
                    rules: {
                        logisticsCompanyName: [
                            {required: true, message: '请选择快递公司!', trigger: ['change', 'blur']},
                            {pattern: /^(?=.*\S).+$/, message: '请选择快递公司!', trigger: ['change', 'blur']}
                        ],
                        logisticsNo: [
                            {required: true, message: '请输入快递单号!', trigger: ['change', 'blur']},
                            {pattern: /^(?=.*\S).+$/, message: '请输入快递单号!', trigger: ['change', 'blur']}
                        ]
                    }
                }
            }
        },
        onReady() {
            const _self = this
            console.log(this.validateForm)
        },
        methods: {
            submit() {
                const _self = this;
                _self.$refs.validateFormRef.validate(valid => {
                    if (valid) {
                        console.log('验证通过', _self.validateForm.value);
                        CommonUtil.alert({
                            title: '提示！',
                            content: '确认添加退货单号吗？',
                            showCancel: true, // 是否显示取消按钮
                            success: function (res) {
                                if (res.cancel) { // 点击取消,默认隐藏弹框
                                } else { // 点击确定
                                    new TbOrderGoodsAfterSaleService().updateTbOrderGoodsAfterSale({
                                        id: _self.objParams.id,
                                        progress: "2",
                                        progress2Remark: _self.validateForm.value.progress2Remark,
                                        refundGoodsLogisticsCompanyType: _self.validateForm.value.logisticsCompanyType,
                                        refundGoodsLogisticsCompanyName: _self.validateForm.value.logisticsCompanyName,
                                        refundGoodsLogisticsNo: _self.validateForm.value.logisticsNo,
                                    }).then(result => {
                                        if (result.status === 'success') {
                                            delete result.data["quantity"];
                                            delete result.data["refundMoney"];
                                            Object.assign(_self.objParams, CommonUtil.deleteNullAttrInObject(result.data));
                                            CommonUtil.toastNavigateBack('退货单号添加成功！');
                                        } else {
                                            CommonUtil.alert(result.message);
                                        }
                                    });
                                }
                            }
                        });
                    } else {
                        console.log('验证失败');
                    }
                });
            }
        }
    }
</script>

<style lang="scss" scoped>
</style>
